<?php
	$list = array();
	$location = array();   
	$type = array();   
	$item_meta=array();
	$list_meta=array();
// Search advance with Taxonomy
	if($_GET['s-location']!=''){
		$location['taxonomy']='location';
		$location['terms']=htmlspecialchars($_GET['s-location']);
		$location['field'] = 'id';
		$list[] = $location;
	}
	if($_GET['s-type']!=''){
		$type['taxonomy']='property-type';
		$type['terms']=htmlspecialchars($_GET['s-type']);
		$type['field'] = 'id';
		$list[] = $type;
	}
	
	$cleanArray = array_merge(array('relation' => 'AND'), $list);
	
// End search advance with Taxonomy

// Start search advance with meta box
	if($_GET['s-bed']!=''){
		if(is_numeric($_GET['s-bed'])){
			$compare="=";
			$s=$_GET['s-bed'];
		}
		else{
			$compare=">=";
			$s=5;
		}
		$item_meta['key'] = 'zon_bedroom';
        $item_meta['value'] = $s;
        $item_meta['compare'] = $compare;
        $list_meta[]=$item_meta;
	}
	
	if($_GET['s-tolet']!=''){
		if(is_numeric($_GET['s-tolet'])){
			$compare="=";
			$s=$_GET['s-tolet'];
		}
		else{
			$compare=">=";
			$s=5;
		}
		$item_meta['key'] = 'zon_tolet';
        $item_meta['value'] = $s;
        $item_meta['compare'] = $compare;
        $list_meta[]=$item_meta;
	}
	
	if($_GET['s-amount']!=''){
		$amount=htmlspecialchars($_GET['s-amount']);
		$amount=explode('-',$amount);
		$min=$amount[0];
		$max=$amount[1];
        
        $item_meta_price_max['key'] = 'zon_price';
        $item_meta_price_max['value'] = array($min,$max);
        $item_meta_price_max['type']='numeric';
        $item_meta_price_max['compare'] = "BETWEEN";
        $list_meta[]=$item_meta_price_max;
	}
	
	$cleanmeta = array_merge(array('relation' => 'AND'), $list_meta);
// End advance search with meta box
	
	$args['post_type'] = 'property';
	$args['showposts'] = get_option('posts_per_page');
	$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
	$args['paged'] = $paged;  
	$args['tax_query'] = $cleanArray; 
	$args['meta_query'] = $cleanmeta; 
	$the_query = new WP_Query( $args );
?>
<?php get_header(); ?>
	<div class="cate-banner">
		<img src="<?php bloginfo("template_url"); ?>/images/cate-banner.png" />
		<div class="row">
			<h1><?php single_cat_title(); ?></h1>
			<?php if(function_exists('zonthemes_breadcrumbs')){zonthemes_breadcrumbs();} ?>
		</div><!---end .row-->
		<div class="clear"></div>
	</div><!--end .cate-banner-->
	<div id="container" class="no-home-bg">
		<div class="row">
		<div class="content single-property">
			<div id="cate-page" class="list-layout">
			<?php echo ($the_query->found_posts > 0) ? '<h3 class="foundPosts">' . $the_query->found_posts. ' properties found</h3>' : '<h3 class="foundPosts">We found no results</h3>';?>
				<ul class="pro-list">
					<?php while ( $the_query->have_posts() ) : $the_query->the_post();?>
					<li>
						<div class="list-img">
							<a href="<?php the_permalink(); ?>" class="view">View</a>
							<a href="<?php the_permalink(); ?>">
								<img class="pro-img" src="<?php echo zon_get_thumbnail('medium'); ?>" alt="<?php the_title(); ?>" title="<?php the_title(); ?>" />
							</a>
						</div>
						<p class="pro-list-title">
							<a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>"><?php the_title(); ?></a>
						</p>
						<?php $comments_count = wp_count_comments(get_the_ID()); ?>
						<p class="pro-list-add"><?php echo get_the_date(); ?>  |   <a href="<?php the_permalink(); ?>#comments"><?php echo $comments_count->total_comments; ?><?php _e(' comments','zonthemes'); ?></a></p>
						<p class="pro-list-desc"><?php zonthemes_cat_string(get_the_excerpt(),50); ?></p>
						<p class="blog-read"><a href="<?php the_permalink(); ?>"><?php _e('Read more >>','zonthemes'); ?></a></p>
						<div class="clear"></div>
					</li>
					<?php endwhile; 
					wp_reset_postdata();?>	
				</ul>
			</div>
		</div><!--end #content-->
		<?php get_sidebar(); ?>
		<div class="clear"></div>
		</div><!--end .row-->
	</div><!--end #container-->
<?php get_footer(); ?>